//////////////////////////////////////////////////////////////////////////////
//                                                                          //
//     Filename: ProtocolTranslator.h                                       //
//  Create date: April 7, 2004                                              //
//                                                                          //
//////////////////////////////////////////////////////////////////////////////
//                                                                          //
//  Description: This file describes the XMLTranslator class, which is      //
//                the base class for a specific group of Protocol Translator//
//                objects that communicate via XML.                         //
//                                                                          //
//////////////////////////////////////////////////////////////////////////////
//       Copyright (c) 2004 - Realtime Gaming.  All rights reserved.        //
//////////////////////////////////////////////////////////////////////////////

#ifndef __XML_TRANSLATOR__
#define __XML_TRANSLATOR__

#include "ProtocolTranslator.h"

//////////////////////////////////////////////////////////////////////////////
// Forward Declarations
//////////////////////////////////////////////////////////////////////////////
class XMLDoc;

//////////////////////////////////////////////////////////////////////////////
// XMLTranslator Class
//////////////////////////////////////////////////////////////////////////////
class XMLTranslator : public ProtocolTranslator
{
public:
	XMLTranslator( Server* pServer, Connection* pParent, uint8 nGameID, uint8 nNumBytesMsgLen );
	virtual ~XMLTranslator();

	// Public Interface
    virtual bool8  ParseIncomingMessage    ( uint8* pInBuff, int32* pIEat, uint8* pOutBuff, uint32 nOutBuffSize );
    virtual bool8  HandleMessage           ( uint8* pOutBuff, uint32 nOutBuffSize, int32* pnOutBytesUsed );
    virtual bool8  TranslateIncomingMessage( uint8* pGameInBuff,  uint32 nGameInBuffSize, uint8* pOutBuff, uint32 nOutBuffSize ) = 0;
    virtual uint32 TranslateOutgoingMessage( uint8* pOutBuff, uint32 nOutBuffSize, uint8* pGameOutBuff, uint32 nGameOutBuffSize, uint32 nTotalGameBytes ) = 0;

	virtual bool8 ReturnErrorMessage(const String& sErrorID, uint8* pOutBuff, uint32 nOutBuffSize );
    virtual bool8 ReturnErrorMessage(const String& sErrorID, const String& sMessage, uint8* pOutBuff, uint32 nOutBuffSize );    // kharmon.  05-04-07.
	virtual bool8 ReturnLoginError( uint8* pOutBuff, uint32 nOutBuffSize );

protected:

	// Helpers
    virtual bool8 LoginUser( XMLDoc* pDoc, String* psPassword = NULL );

	bool8 AddLoginVersionInfo( uint32& nOffset, XMLDoc* pDoc, uint8* pGameInBuff );
	bool8 AddLoginID( uint32& nOffset, XMLDoc* pDoc, uint8* pGameInBuff );
	bool8 AddPassword( uint32& nOffset, XMLDoc* pDoc, uint8* pGameInBuff );
	bool8 AddLoginMachID( uint32& nOffset, XMLDoc* pDoc, uint8* pGameInBuff );
	bool8 AddLoginCreditValue( uint32& nOffset, XMLDoc* pDoc, uint8* pGameInBuff );
	bool8 AddLoginMoneyType( uint32& nOffset, XMLDoc* pDoc, uint8* pGameInBuff );
	bool8 LoadStringTableForLanguage( XMLDoc* pDoc );
    bool8 ReturnLocaleInfo( uint8* pOutBuff, uint32 nOutBuffSize );

	// CSN-7075: New Authentication
	bool8 AddAuthenticationToken( uint32& nOffset, XMLDoc* pDoc, uint8*  pGameInBuff );

	// CSN-7534: Client type
	bool8 AddClientID( uint32& nOffset, XMLDoc* pDoc, uint8*  pGameInBuff );

	// Common Messages
	bool8 TranslateGenericOutError( uint8* pOutBuff, uint32 nOutBuffSize, uint8* pGameOutBuff, uint32 nGameOutBuffSize, uint8 nMsgLenSize );

	bool8 TranslateInBalance ( XMLDoc* pDoc, uint8* pGameInBuff,  uint32 nGameInBuffSize, uint8 nMsgLenSize);
	bool8 TranslateOutBalance( uint8* pOutBuff, uint32 nOutBuffSize, uint8* pGameOutBuff, uint32 nGameOutBuffSize, uint8 nMsgLenSize );

	// AddCurrencyOutput. CSN-11204
	bool8 AddCurrencyOutput( XMLDoc *doc );

protected:
    XMLDoc* m_pDoc;
	bool8   m_bEncryptedCredentials;

public:
    String  m_sMsgID;
};

#endif // #ifndef __XML_TRANSLATOR__